<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = $_SESSION['user'];

$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2)
	header("Location: home.php");
?>
<!doctype html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">
<link rel="icon" href="http://veteranboosters.com/orders/images/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://veteranboosters.com/orders/images/favicon.ico" type="image/x-icon"/>
  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">

  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">

  <!-- Use title if it's in the page YAML frontmatter -->
  <title>Veteran Boosters Member Area</title>

  <!--[if lt IE 9]>
  <script src="../../javascripts/vendor/html5shiv.js" type="text/javascript"></script>
  <script src="../../javascripts/vendor/excanvas.js" type="text/javascript"></script>
  <![endif]-->

  <link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="javascripts/application.js" type="text/javascript"></script>
</head>

<?php
	include("top.php");
?>

  <div class="container-fluid padded">
    <div class="row-fluid">

      <!-- Breadcrumb line -->

      <div id="breadcrumbs">
               <div class="breadcrumb-button blue">
                  <span class="breadcrumb-label"><i class="icon-home"></i> Home</span>
                  <span class="breadcrumb-arrow"><span></span></span>
               </div>

               <div class="breadcrumb-button">
                  <span class="breadcrumb-label">
                     <i class="icon-user"></i> Members
                  </span>
                  <span class="breadcrumb-arrow"><span></span></span>
               </div>
               
               <div class="breadcrumb-button">
                  <span class="breadcrumb-label">
                     <i class="icon-reorder"></i> Admin settings                  </span>
                  <span class="breadcrumb-arrow"><span></span></span>
               </div>
            </div>
    </div>
  </div>

  <div class="container-fluid padded">
  <div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Settings</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
                     <td>Name</td>
                     <td>Value</td>
					 <td>Action</td>
                  </tr>
               </thead>
               <tbody>
			   <?php
					$result = mysql_query("SELECT * FROM option_list") or die(mysql_error());

					while($row = mysql_fetch_array($result))
					{
						echo "<tr id = 'option_".$row['id']."'><td>".$row['name']."</td>";
						
						if($row['name'] == "Admin payments")
						{
							$select = "<select onchange = 'update_button(".$row['id'].");'>";

							if($row['value'] == 'Off')
							{
								$select .= "<option selected = 'selected'>Off</option>";
								$select .= "<option>On</option>";
							}
							else
							{
								$select .= "<option>Off</option>";
								$select .= "<option selected = 'selected'>On</option>";
							}

							echo "<td>".$select."</td>";
						}
						else
						{
							echo "<td><input onkeyup = 'update_button(".$row['id'].");' type = 'text' value = '".$row['value']."' /></td>";
						}
						echo "<td><a href='#' class='btn btn-info'>Update</a></td></tr>";
					}
			   ?>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
<div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Per Win Pricing</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
                     <td>Tier</td>
                     <td>Division 5</td>
					 <td>Division 4</td>
					 <td>Division 3</td>
					 <td>Division 2</td>
					 <td>Division 1</td>
					 <td>Action</td>
                  </tr>
               </thead>
               <tbody>
			   <tr>
			   <?php
					$bronzeArray = array();
					$silverArray = array();
					$goldArray = array();
					$platinumArray = array();
					$diamondArray = array();

					$result = mysql_query("SELECT * FROM pricing WHERE tier = 'bronze' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($bronzeArray, $row);
					}

					$result = mysql_query("SELECT * FROM pricing WHERE tier = 'silver' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($silverArray, $row);
					}

					$result = mysql_query("SELECT * FROM pricing WHERE tier = 'gold' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($goldArray, $row);
					}

					$result = mysql_query("SELECT * FROM pricing WHERE tier = 'platinum' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($platinumArray, $row);
					}

					$result = mysql_query("SELECT * FROM pricing WHERE tier = 'diamond' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($diamondArray, $row);
					}
			   ?>
					<td>Bronze</td>
					<form action = "update_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "bronze" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $bronzeArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $bronzeArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $bronzeArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $bronzeArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $bronzeArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Silver</td>
					<form action = "update_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "silver" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $silverArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $silverArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $silverArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $silverArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $silverArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Gold</td>
					<form action = "update_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "gold" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $goldArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $goldArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $goldArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $goldArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $goldArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Platinum</td>
					<form action = "update_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "platinum" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $platinumArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $platinumArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $platinumArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $platinumArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $platinumArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Diamond</td>
					<form action = "update_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "diamond" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $diamondArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $diamondArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $diamondArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $diamondArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $diamondArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
<div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Division Pricing</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
                     <td>Tier</td>
                     <td>Division 5</td>
					 <td>Division 4</td>
					 <td>Division 3</td>
					 <td>Division 2</td>
					 <td>Division 1</td>
					 <td>Action</td>
                  </tr>
               </thead>
               <tbody>
			   <tr>
			   <?php
					$bronzeArray = array();
					$silverArray = array();
					$goldArray = array();
					$platinumArray = array();
					$diamondArray = array();

					$result = mysql_query("SELECT * FROM division_pricing WHERE tier = 'bronze' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($bronzeArray, $row);
					}

					$result = mysql_query("SELECT * FROM division_pricing WHERE tier = 'silver' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($silverArray, $row);
					}

					$result = mysql_query("SELECT * FROM division_pricing WHERE tier = 'gold' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($goldArray, $row);
					}

					$result = mysql_query("SELECT * FROM division_pricing WHERE tier = 'platinum' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($platinumArray, $row);
					}

					$result = mysql_query("SELECT * FROM division_pricing WHERE tier = 'diamond' ORDER BY division DESC");

					while($row = mysql_fetch_array($result))
					{
						array_push($diamondArray, $row);
					}
			   ?>
					<td>Bronze</td>
					<form action = "update_division_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "bronze" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $bronzeArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $bronzeArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $bronzeArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $bronzeArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $bronzeArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Silver</td>
					<form action = "update_division_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "silver" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $silverArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $silverArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $silverArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $silverArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $silverArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Gold</td>
					<form action = "update_division_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "gold" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $goldArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $goldArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $goldArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $goldArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $goldArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Platinum</td>
					<form action = "update_division_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "platinum" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $platinumArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $platinumArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $platinumArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $platinumArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $platinumArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   <tr>
					<td>Diamond</td>
					<form action = "update_division_pricing.php" method = "post">
					<input type = "hidden" name = "tier" value = "diamond" />
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "5" type = 'text' value = '<?php echo $diamondArray[0]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "4" type = 'text' value = '<?php echo $diamondArray[1]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "3" type = 'text' value = '<?php echo $diamondArray[2]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "2" type = 'text' value = '<?php echo $diamondArray[3]['price']; ?>' /></td>
					<td><input style = "width: 25px; margin-bottom: 0px;" name = "1" type = 'text' value = '<?php echo $diamondArray[4]['price']; ?>' /></td>
					<td><input type = "submit" value = "Update" class='btn btn-info' /></td>
					</form>
			   </tr>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
</div>
<script>
function update_button (id)
{
	var row = document.getElementById("option_"+id);
	var value = row.children[1].children[0].value;
	var url = "update_options.php?id="+id+"&value="+value;
	row.children[2].children[0].href = url;
}
</script>
<?php
	include("bottom.php");
?>
